def search():
    mark = True
    student_query = []
    while mark:
        id = ""
        name = ""
        if os.path.exists(filename):
            mode = input("按ID查输入1；按姓名查输入2：")
            if mode == "1":
                id = input("请输入学生ID：")
            elif mode == "2":
                name = input("请输入学生姓名：")
            else:
                print("您输入有误，请重新输入！")
                search()
            with open(filename,'r') as file:
                student = file.readlines()
                for list in student:
                    d = dict(eval(list))
                    if id != "":
                        if d['id'] == id:
                            student_query.append(d)
                    elif name != "":
                        if d['name'] == id:
                            student_query.append(d)
                    show_student(student_query)
                    student_query.clear()
                    inputMark = input("是否继续添加？(y/n)：")
                    if inputMark == "y":
                        mark = True
                    else:
                        mark = False
                else:
                    print("暂未保存数据信息")
                    return

def show_student(stdList):
    if not stdList:
        print("无数据信息")
        return
    format_title = "{:^6}{:^12}\t{:^8}\t{:^10}\t{:^10}"
    print(format_title.format("ID","名字","英语成绩","python成绩","总成绩"))
    format_data = "{:^6}{:^12}\t{:^12}\t{:^12}\t{:^12}"
    for info in stdList:
        print(format_data.format(info.get("id"),info.get("name"),str(info.get("english")),str(info.get("python")),str(info.get("english")+info.get("python")).center(12)))
              
    